package payroll.trans;

import java.util.Map;
import java.util.LinkedHashMap;

import payroll.Employee;
import payroll.Paycheck;
import payroll.PayrollDatabase;
import payroll.Transaction;

public class PaydayTransaction implements Transaction {

    private Map<Integer, Paycheck> paychecks = new LinkedHashMap<>();

    @Override
    public void execute() {
        // 为每个雇员支付薪金
        for (Employee e : PayrollDatabase.listAllEmployees()) {
            // 创建一个 Paycheck
            Paycheck paycheck = new Paycheck();
            // 计算工资并填写支付方式到 Paycheck
            e.pay(paycheck); // 根据计算工资的方式，支付方式，填写 paycheck
            // 保存 Paycheck
            paychecks.put(e.getEmpId(), paycheck);
        }
    }

    public Paycheck getPaycheckOf(int empId) {
       return paychecks.get(empId);
    }

}
